package com.li.springbootproject.spring.factorydemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021年11月18日 20:20:00
 */
@Component
public class CustomerFactory {

    /**
     * 对象 Map
     */
    private static final Map<String, CustomerService> OBJECT_MAP = new HashMap<>();


    /**
     * set 方法注入
     *
     * @param customerService
     */
    @Autowired
    private void setObjectMap(List<CustomerService> customerService) {
        for (CustomerService service : customerService) {
            OBJECT_MAP.put(service.getUserName(), service);
        }
    }

    /**
     * 获取 CustomerService 的实例
     *
     * @param type
     * @return
     */
    public static CustomerService getInstance(String type) {
        return OBJECT_MAP.get(type);
    }

}
